public class L459 {

    public static void main(String[] args) {
        boolean flag = new Solution().repeatedSubstringPattern("abac");
        System.out.println(flag);
    }


    static class Solution {
        public boolean repeatedSubstringPattern(String s) {
            char[] chars = s.toCharArray();
            int i = 0;
            int length = chars.length;
            int[] next = new int[length];
            next[i] = 0;
            for (int j = 1; j < length; j++) {
                while (i > 0 && chars[i] != chars[j]) {
                    i = next[i - 1];
                }
                if (chars[i] == chars[j]) {
                    i++;
                }
                next[j] = i;
            }
            int k = next[length - 1];
            if (k == 0) {
                return false;
            }
            return length % (length - k) == 0;

        }
    }
}
